import requests
from .login_token import get_token
import json

"""此模块为对requests请求方法的一个封装"""
token = None


def do_rest(url, param, method):
    global token
    if token == None:
        token = get_token()
    headers = {
        "token": token
    }

    if method == 'post':
        params = json.dumps(param)
        return requests.post(url, data=params, headers=headers, verify=False)
    elif method == 'get':
        params = json.dumps(param)
        return requests.get(url, params=params, headers=headers, verify=False)
    elif method == 'get1':
        return requests.get(url, params=param, headers=headers, verify=False)
    elif method == 'post1':
        # headers['Content-Type'] = 'multipart/form-data; boundary=----WebKitFormBoundaryABTpAA7g1yPO9MHA'
        return requests.post(url, files=param, headers=headers, verify=False)
